<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function cleartbox()
{	
	document.getElementById("Sea_Sch").innerHTML="";
}
</script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.form1.SchName.value=val;
document.getElementById("List").innerHTML="";
}
</script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
 else
   {
   if(isset($_POST['ADD']))
{
 $SchName=$_POST['SchName'];
$Exam_Name=$_POST['Exam_Name'];
$Subject=$_POST['Subject'];
$Year=$_POST['Year'];
$No_Of_Sat_Students=$_POST['No_Of_Sat_Students'];
$No_Of_Passed_Students=$_POST['No_Of_Passed_Students'];
$name=explode(",",$SchName);
    $nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $School_Id=$row['School_Id'];
}
 if($SchName==""||$Exam_Name==""||$Year==""||$Subject=="")
	   {
	   $_SESSION['errorin']="All details are required Please fill all!";
	   }
	   if($SchName!=""&&$Exam_Name!=""&&$Year!=""&&$Subject!="")
	   {
	  $Ex_Che=mysql_query("SELECT * FROM exam WHERE School_Id='$School_Id' AND Exam_Name='$Exam_Name' AND Year='$Year' AND Subject='$Subject'");
if(mysql_num_rows($Ex_Che)!=0)
		{
			$_SESSION['errorexi']="Sorry this Exam's record already exists";
		}
		else
		{
		if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  
   if($School_Id==$Own_School_Id)
	{
		require_once 'insertexam.php';
		}
		 else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
		}
		}
		else if($_SESSION['Access_Type']=="Administrator")
{
require_once 'insertexam.php';
}   
   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	}
?>
 <?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<br/>
<div id="lefttablereg">
<form name="form1" action="#" method="POST">
<table>
<tr>
<td width="502" height="21" class="err">
<?php
if(isset($_POST['ADD']))
{
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
		
	}
	if(isset($_SESSION['errornotallo']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
if(isset($_SESSION['errorexi']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errorexi'];
unset($_SESSION['errorexi']);
}
}
?>
</font></td>
</tr>
</table>
   <table width="531" border="0" class="tablefontv">
     <tr>
       <td width="42"><font color="red" size="+2"><p align="center">*</p></font></td>
       <td width="178" height="26" scope="row">School's Name</td>
       <td width="12">:-</td>
	   
       <td width="281"> <?php
	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40'/>";
}
	  ?></td>
     </tr>
     <tr>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Exam Name</td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['ADD']))
{
echo '<td>';
echo "<input type='text' name='Exam_Name' value='$Exam_Name'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Exam_Name'/>";
echo '</td>';

}?>
       <td></td>
     </tr>
<tr>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Subject</td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['ADD']))
{
echo '<td>';
echo "<input type='text' name='Subject' value='$Subject'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Subject'/>";
echo '</td>';

}?>
       <td></td>
     </tr>
     <tr>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Year</td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['ADD']))
{
echo '<td>';
echo "<input type='text' name='Year' value='$Year'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Year'/>";
echo '</td>';

}?>
       <td></td>
     </tr>
     <tr>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Number Of Sat Students</td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['ADD']))
{
echo '<td>';
echo "<input type='text' name='No_Of_Sat_Students' value='$No_Of_Sat_Students'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='No_Of_Sat_Students'/>";
echo '</td>';

}?>
       <td></td>
     </tr>
     <tr>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Number Of Passed Students</td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['ADD']))
{
echo '<td>';
echo "<input type='text' name='No_Of_Passed_Students' value='$No_Of_Passed_Students'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='No_Of_Passed_Students'/>";
echo '</td>';

}?>
       <td></td>
     </tr>
     <tr>
       <td><a href="insert.php"></a></td>
       <td colspan="3"><p><a href="insert.php" class="reset"><strong>Reset | </strong></a>
         <input type="submit" value="ADD" name="ADD" class="buttonok"/>
     </td>
       </tr>
   </table>
</form>
</div>

<div id="righttablereg">
<?php
 if($_SESSION['OK']!="OK")
{
?>
 <div class="suggestionListsch" id="List"></div>
<?php
}
		if(isset($_POST['ADD']))
{
date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
if($_SESSION['OK']=="OK")
{
if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM exam WHERE School_Id='$Own_School_Id'");
   echo '<br/>';
if(mysql_num_rows($result)!=0)
   {
  echo '<table width="500" border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td width="100"><b>School_Id</b></td>
<td width="100"><b>Exam Name</b></td>
<td width="100"><b>Subject</b></td>
<td width="100"><b>Year</b></td>
<td width="100"><b>No Of Sat_Students</b></td>
<td width="130"><b>No Of_Passed Students</b></td>
<td width="130"><b>Last Updated Date</b></td>
</tr>';
while($row=mysql_fetch_array($result))
  {
	$School_Id=$_SESSION['School_Id'];
	$Exam_Name=$_SESSION['Exam_Name'];
	$Year=$_SESSION['Year'];
$Subject=$_SESSION['Subject'];
    if($row['School_Id']==$School_Id&&$row['Exam_Name']==$Exam_Name&&$row['Year']==$Year&&$row['Subject']==$Subject)
   {
   echo '<tr bgcolor="#936">';
    echo '<td width="100">'.$row['School_Id'].'</td>';
    echo '<td width="100">'. $row['Exam_Name'].'</td>';
echo '<td width="100">'. $row['Subject'].'</td>';
	echo '<td width="100">'. $row['Year'].'</td>';
    echo '<td width="100">'.$row['No_Of_Sat_Students'].'</td>';
    echo '<td width="130">'.$row['No_Of_Passed_Students'].'</td>';
	echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
      echo '</tr>';
	  unset($_SESSION['School_Id']);
	  unset($_SESSION['Exam_Name']);
	  unset($_SESSION['Year']);
 unset($_SESSION['Subject']);
  }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td width="100">'.$row['School_Id'].'</td>';
    echo '<td width="100">'. $row['Exam_Name'].'</td>';
 echo '<td width="100">'. $row['Subject'].'</td>';
	echo '<td width="100">'. $row['Year'].'</td>';
    echo '<td width="100">'.$row['No_Of_Sat_Students'].'</td>';
    echo '<td width="130">'.$row['No_Of_Passed_Students'].'</td>';
	echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
  echo '</tr>';
  }
  }
   echo "</table>";
   echo '</div>';
  }
 }
 }
 if($_SESSION['Access_Type']=="Administrator")
{
$result=mysql_query("SELECT * FROM exam");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {
    echo '<table width="500" border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td width="100"><b>School Id</b></td>
<td width="100"><b>Exam Name</b></td>
<td width="100"><b>Subject</b></td>
<td width="100"><b>Year</b></td>
<td width="100"><b>No Of Sat Students</b></td>
<td width="130"><b>No Of Passed Students</b></td>
<td width="130"><b>Last Updated Date</b></td>
</tr>';
while($row=mysql_fetch_array($result))
  {
  $School_Id=$_SESSION['School_Id'];
	$Exam_Name=$_SESSION['Exam_Name'];
	$Year=$_SESSION['Year'];
$Subject=$_SESSION['Subject'];
  

  if($row['School_Id']==$School_Id&&$row['Exam_Name']==$Exam_Name&&$row['Year']==$Year&&$row['Subject']==$Subject)
  {
      echo '<tr bgcolor="#936">';
    echo '<td width="100">'.$row['School_Id'].'</td>';
    echo '<td width="100">'. $row['Exam_Name'].'</td>';
   echo '<td width="100">'. $row['Subject'].'</td>';
	echo '<td width="100">'. $row['Year'].'</td>';
    echo '<td width="100">'.$row['No_Of_Sat_Students'].'</td>';
    echo '<td width="130">'.$row['No_Of_Passed_Students'].'</td>';
	echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
      echo '</tr>';
	  unset($_SESSION['School_Id']);
	  unset($_SESSION['Exam_Name']);
	  unset($_SESSION['Year']);
unset($_SESSION['Subject']);
  }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td width="100">'.$row['School_Id'].'</td>';
    echo '<td width="100">'. $row['Exam_Name'].'</td>';
echo '<td width="100">'. $row['Subject'].'</td>';
	echo '<td width="100">'. $row['Year'].'</td>';
    echo '<td width="100">'.$row['No_Of_Sat_Students'].'</td>';
    echo '<td width="130">'.$row['No_Of_Passed_Students'].'</td>';
	echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
	echo '</tr>';
  }
  }
   echo "</table>";
   echo '</div>';
  }
  }
  unset($_SESSION['OK']);
  }
  }
  ?>
 </div>
</div>
</div>
</div>
<div id="sidebar"><br/>
<div id="partners" class="boxed">
			<h2 class="title">EXAMS</h2>
            </div>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
}
?>
</body>
</html>